﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "教学运行管理 - 排课 - 打印教室课表");
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		
		termId = event.getArg("TID");
		buildId = event.getArg("BID");
		
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		currentTab = event.getArg("TabID", "labBuilding");
		
		rs_build = queryNew("b_id");
		rs_clsroom = queryNew("cr_id");
		
		rs_buildEntity = queryNew("b_id");
		
		targetArgs = structNew();
		
		if ( len(termId) ) {
			
			structInsert(targetArgs, "TID", termId);
			
			/* 如果有学期信息传递过来 */
			sql = "	SELECT
						a.b_id,a.b_name,a.b_floors
					FROM
						t_building a
					WHERE
						EXISTS(
							SELECT 1 FROM t_clsroom_forcourse b INNER JOIN t_clsroom_timetable bct ON bct.crtime_id = b.crtime_id 
							INNER JOIN t_classroom bc ON bc.cr_id = bct.cr_id
							WHERE bc.b_id = a.b_id AND bct.term_id = :termId 
						)
					ORDER BY
						a.b_id";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
			rs_build = queryObj.execute(sql = sql).getResult();
			
			if ( len(buildId) ) {

				sql = "	SELECT
							b.b_id,b.b_name
						FROM
							t_building b
						WHERE
							b.b_id = :buildId ";
				
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "buildId", value = buildId, cfsqltype = "cf_sql_char");
				rs_buildEntity = queryObj.execute(sql = sql).getResult();
				
				currentTab = "labClassroom";

				sql = "	SELECT
							ac.cr_id,ac.classroom,ct.cr_type_name,ac.sits_course,ac.cr_floor,
							SUM(act.cellrelay) l_sum,
							SUM(CASE WHEN act.wdidx = '1' THEN act.cellrelay ELSE 0 END) w1_sum,
							SUM(CASE WHEN act.wdidx = '2' THEN act.cellrelay ELSE 0 END) w2_sum,
							SUM(CASE WHEN act.wdidx = '3' THEN act.cellrelay ELSE 0 END) w3_sum,
							SUM(CASE WHEN act.wdidx = '4' THEN act.cellrelay ELSE 0 END) w4_sum,
							SUM(CASE WHEN act.wdidx = '5' THEN act.cellrelay ELSE 0 END) w5_sum,
							SUM(CASE WHEN act.wdidx = '6' THEN act.cellrelay ELSE 0 END) w6_sum,
							SUM(CASE WHEN act.wdidx = '7' THEN act.cellrelay ELSE 0 END) w7_sum
						FROM
							t_clsroom_forcourse a INNER JOIN t_clsroom_timetable act ON act.crtime_id = a.crtime_id INNER JOIN t_classroom ac ON ac.cr_id = act.cr_id
							INNER JOIN t_classroom_type ct ON ct.cr_type = ac.cr_type
						WHERE
							ac.b_id = :buildId 
							AND
							act.term_id = :termId 
						GROUP BY
							ac.cr_id,ac.classroom,ct.cr_type_name,ac.sits_course,ac.cr_floor
						ORDER BY
							ac.cr_floor,ac.classroom";
							
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "buildId", value = buildId, cfsqltype = "cf_sql_char");
				queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
				rs_clsroom = queryObj.execute(sql = sql).getResult();
				
			}
			
				
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 building"></i>学期教学场地安排情况
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<cfif termId eq "">
					<!-- termSelector -->
					<cfoutput>#event.getArg("termSelector")#</cfoutput>
					<!-- /termSelector -->
				</cfif>
				
				<cfif len(termId)>
					
					<div class="UItab">
						<div class="tabLables">
							<span <cfif currentTab eq "labBuilding">class="active"</cfif> id="labBuilding" tabTarget="Building">教学楼</span>
							<cfif len(buildId)>
								<span <cfif currentTab eq "labClassroom">class="active"</cfif> id="labClassroom" tabTarget="Classroom">教室使用明细</span>
							</cfif>
						</div>
					</div>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
						
							/* init Tab */
							$("div.tabContent[@id!=' + $targetID + ']").hide();
							$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
							$("div.tabLables > span").click(function(){
								var $targetID = $(this).attr("tabTarget");
							
								$("div.tabLables span").removeClass("active");
								$(this).addClass("active");
							
								$("div.tabContent[@id!=' + $targetID + ']").hide();
								$("div.tabContent#" + $targetID).show();
							});
						
						});
						// -->
						//]]>
					</script>
					
					<div id="Building" class="tabContent">
						
						<div class="noticeBlock">
							<h3>学期排课教学楼</h3>
							<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期教学任务安排于 <em><cfoutput>#rs_build.recordCount#</cfoutput></em> 个教学楼中进行.</p>
							<hr/>
						</div>
						
						<cfif rs_build.recordCount>
							<div class="clearfix">
								<div class="UICardTable">
									
                                    <cfloop query="rs_build">
										<cfset structInsert(targetArgs, "BID", rs_build.b_id, true) />
											
										<dl>
											<dt>
												<a href="<cfoutput>#buildURL('classroomArrange', targetArgs)#</cfoutput>">
													<em class="building"><!--imgholder--></em>
													<dd>
														<h3><cfoutput>#rs_build.b_name#</cfoutput></h3>
														<div><cfoutput>#dictAdvice.getBuildingFloorSummary(rs_build.b_floors)#</cfoutput></div>
													</dd>
												</a>
											</dt>
										</dl>
											
									</cfloop>
									
								</div>
							</div>
						</cfif>
						
					</div>
					
					<div id="Classroom" class="tabContent">
						
						<cfif rs_buildEntity.recordCount>
							
							<cfset structInsert(targetArgs, "BID", rs_buildEntity.b_id, true ) />
							
							<div class="noticeBlock">
								<div class="operation">
									<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('buildingCoursePrint', targetArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">打印教室课表</span></a>
								</div>
								<h3><cfoutput>#rs_buildEntity.b_name#</cfoutput></h3>
								<p>
									<span class="img icon16x16 message"></span>
									<em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 
									安排了课程教学任务教室 <em><cfoutput>#rs_clsroom.recordCount#</cfoutput></em> 个
									.
								</p>
								<hr/>
							</div>
						</cfif>

						<cfif rs_clsroom.recordCount>
						
							<table class="UIEditable">
								<thead>
									<tr>
										<td width="18"></td>
										<td>教室</td>
										<td>类别</td>
										<td>排课座次</td>
										<td>楼层</td>
										<td>周学时</td>
										<td>一</td>
										<td>二</td>
										<td>三</td>
										<td>四</td>
										<td>五</td>
										<td>六</td>
										<td>日</td>
									</tr>
								</thead>
								<tbody>
									<cfset row = 0 />
                                    <cfloop query="rs_clsroom">
										<cfset row++ />
										<cfset structInsert(targetArgs, "CRID", rs_clsroom.cr_id, true) />
									
										<tr class="editRows">
											<td class="index"><cfoutput>#row#</cfoutput></td>
											<td><a href="<cfoutput>#buildURL('classroomCourseTable', targetArgs)#</cfoutput>"><cfoutput>#rs_clsroom.classroom#</cfoutput></a></td>
											<td><cfoutput>#rs_clsroom.cr_type_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.sits_course#</cfoutput></span></td>
											<td><cfoutput>#dictAdvice.getFloorString( rs_clsroom.cr_floor )#</cfoutput></td>
											<td><span class="numeric bold"><cfoutput>#rs_clsroom.l_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w1_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w2_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w3_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w4_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w5_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w6_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w7_sum#</cfoutput></span></td>
										</tr>
									</cfloop>
								</tbody>
							</table>
						
						</cfif>
					
					</div>

				</cfif>
				
			</div>
		</li>
	</ul>
</div>